package com.soft.admin.web;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.soft.admin.dto.MenuToDTO;
import com.soft.admin.service.MenuService;

@Controller
@RequestMapping(value = "/admin/menu.do")
public class MenuController extends BaseController {
	private MenuService menuService;
	
	@RequestMapping(params = "index")
	public String get(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.menuService.get();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextodetail")
	public String getDetail(HttpServletResponse response, HttpServletRequest request, Integer id) 
			throws IOException {
		String res = this.menuService.getDetail(id);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextoaction")
	public String getAction(HttpServletResponse response, HttpServletRequest request, Integer id) 
			throws IOException {
		String res = this.menuService.getAction();
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "indextoimg")
	public String getImg(HttpServletResponse response, HttpServletRequest request) 
			throws IOException {
		String res = this.menuService.getImg(request);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "add")
	public String add(HttpServletResponse response, HttpServletRequest request, MenuToDTO params, 
			Integer parent) throws IOException {
		String res = this.menuService.addOrEdit(params, parent);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "edit")
	public String edit(HttpServletResponse response, HttpServletRequest request, MenuToDTO params, 
			Integer parent) throws IOException {
		String res = this.menuService.addOrEdit(params, parent);
		response.getWriter().print(res);
		return null;
	}
	
	@RequestMapping(params = "remove")
	public String remove(HttpServletResponse response, HttpServletRequest request, Integer id) 
			throws IOException {
		String res = this.menuService.remove(id);
		response.getWriter().print(res);
		return null;
	}

	@Autowired
	public void setMenuService(MenuService menuService) {
		this.menuService = menuService;
	}
}
